<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>pthread_setspecific</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_007_1714">&nbsp;</a>NAME</h4><blockquote>
pthread_setspecific, pthread_getspecific - thread-specific data management
</blockquote><h4><a name = "tag_000_007_1715">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="pthread.h.html">pthread.h</a>&gt;

int pthread_setspecific(pthread_key_t <i>key</i>, const void *<i>value</i>);
void *pthread_getspecific(pthread_key_t <i>key</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_007_1716">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>pthread_setspecific()</i>
function associates a thread-specific
<i>value</i>
with a
<i>key</i>
obtained via a previous call to
<i><a href="pthread_key_create.html">pthread_key_create()</a></i>.
Different threads may bind different values to the same key.
These values are typically pointers to blocks of dynamically allocated memory
that have been reserved for use by the calling thread.
<p>
The
<i>pthread_getspecific()</i>
function returns the value currently bound to the specified
<i>key</i>
on behalf of the calling thread.
<p>
The effect of calling
<i>pthread_setspecific()</i>
or
<i>pthread_getspecific()</i>
with a
<i>key</i>
value not obtained from
<i><a href="pthread_key_create.html">pthread_key_create()</a></i>
or after
<i>key</i>
has been deleted with
<i><a href="pthread_key_delete.html">pthread_key_delete()</a></i>
is undefined.
<p>
Both
<i>pthread_setspecific()</i>
and
<i>pthread_getspecific()</i>
may be called from a thread-specific data destructor function.
However, calling
<i>pthread_setspecific()</i>
from a destructor may result in lost storage or infinite loops.
<p>
Both functions may be implemented as macros.
</blockquote><h4><a name = "tag_000_007_1717">&nbsp;</a>RETURN VALUE</h4><blockquote>
The function
<i>pthread_getspecific()</i>
returns the thread-specific data value
associated with the given
<i>key</i>.
If no thread-specific data value is associated with
<i>key</i>,
then the value NULL is returned.
<p>
If successful, the
<i>pthread_setspecific()</i>
function returns zero.
Otherwise, an error number is returned to indicate the error.
</blockquote><h4><a name = "tag_000_007_1718">&nbsp;</a>ERRORS</h4><blockquote>
The 
<i>pthread_setspecific()</i>
function will fail if:
<dl compact>

<dt>[ENOMEM]<dd>
Insufficient memory exists to associate the value with the key.

</dl>
<p>
The
<i>pthread_setspecific()</i>
function may fail if:
<dl compact>

<dt>[EINVAL]<dd>
The key value is invalid.

</dl>
<p>
No errors are returned from
<i>pthread_getspecific()</i>.
<p>
These functions will not return an error code of [EINTR].
</blockquote><h4><a name = "tag_000_007_1719">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1720">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1721">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1722">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="pthread_key_create.html">pthread_key_create()</a></i>,
<i><a href="pthread.h.html">&lt;pthread.h&gt;</a></i>.
<br>
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from the POSIX Threads Extension (1003.1c-1995)
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

